#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#include "bloom_filter.h"
#include "typecast_config.h"

void test_transformation(char * hex) 
{ 		
	char buf[255]; 
	bloom_filter_t filter; 
	int i; 
	printf("%s\n", hex); 
	hex_string_to_bloom_filter(hex, filter); 
	for(i=0; i<sizeof(bloom_filter_t); i++) { 
		printf("%02x", filter[i]); 
	}
	printf("\n"); 		
	bloom_filter_to_hex_string(filter, buf, sizeof(buf)); 
	printf("%s\n", buf); 	
}

void test_subfilter() 
{ 
	char * hex1 = "01020304ABCDFF"; 
	char * hex2 = "00020304ABCDEF"; 
	char * hex3 = "11020304ABCDEF";
	bloom_filter_t filter1; 
	bloom_filter_t filter2; 
	bloom_filter_t filter3; 
	
	hex_string_to_bloom_filter(hex1,  filter1); 
	hex_string_to_bloom_filter(hex2,  filter2); 
	hex_string_to_bloom_filter(hex3,  filter3); 
	
	printf("filter1=%s\n", hex1); 
	printf("filter2=%s\n", hex2); 
	printf("filter3=%s\n", hex3); 
	printf("is_subfilter(filter1, filter2)=%d\n", is_subfilter(filter1, filter2)); 
	printf("is_subfilter(filter1, filter3)=%d\n", is_subfilter(filter1, filter3)); 
	printf("is_subfilter(filter2, filter3)=%d\n", is_subfilter(filter2, filter3)); 
	printf("is_subfilter(filter3, filter2)=%d\n", is_subfilter(filter3, filter2)); 
}

			
int main(int argc, char **argv) 
{ 
	read_typecast_config_file(); 
	DumpTypeCastRoutingTable(stdout); 
	
	/*
	if (argc <= 1) { 
		printf("usage: %s hex_string\n", argv[0]); 
		exit(1); 
	}	
	char * hex = argv[1]; 		
	test_transformation(hex); 
	test_subfilter(); 
	*/
	
}

